import numpy as np

def show_ls(ls):
    for i in ls:
        print(i)

class Point:
    def __init__(self, xy: tuple, y=None):
        if y == None:
            x, y = xy
        else:
            x = xy

        self.x = x
        self.y = y


class Shape:
    def __init__(self, points: np.ndarray):
        self.points = points
        self.center = points.sum(0)

    def getFarthestPointInDirection(self, d):
        return 1

if __name__ == '__main__':
    a_0 = [
        [4, 11],
        [4, 5],
        [9, 9],
    ]

    b_0 = [
        [5, 7],
        [7, 3],
        [10, 2],
        [12, 7],
    ]

    aa = np.array(a_0)
    bb = np.array(b_0)

    sa = Shape(aa)
    sb = Shape(bb)


    def conv_to_np(a, b):
        if not isinstance(a, np.ndarray) or isinstance(b, np.ndarray):
            a = np.array(a)
            b = np.array(b)
        return a, b

    def to_np(ls: list):
        ret = []
        for i in ls:
            if not isinstance(i, np.ndarray):
                r = np.array(i)
            else:
                r = i
            ret.append(r)
        return ret

    def get_d_bycross(a, b):
        # 得到垂直于ab且朝向原点方向的法向量d, d方向上最远的Minkowski点即为C
        a, b = conv_to_np(a, b)

        # 三维变二维
        ret_size = a.size
        if ret_size == 2:
            a = np.hstack([a, 0])
            b = np.hstack([b, 0])

        ab = b - a
        ao = 0 - a
        oc = np.cross(np.cross(ab, ao), ab)

        return oc[:-1]      # 变回2维





    if 1:
        a = (0, 1)
        b = (1, 0)
        c = (-1, -1)

        a, b, c = to_np([a, b, c])
        a, b, c

        ab = b - a
        ao = -a
        ac = c - a

        d = get_d_bycross(a, b)

        def cross_2d(a, b):
            # 2d向量的外积
            a, b = conv_to_np(a, b)

            # 二维变三维
            if a.size == 2:
                a = np.hstack([a, 0])
            if b.size == 2:
                b = np.hstack([b, 0])

            oc = np.cross(a, b)

            return oc

        def get_abc_cross(a, b, c):
            """
            # 获得二维平面中, 三个向量的连续外积的结果.
            # 将返回一个二维向量, 如ABN=A*B*B的向量垂直于B,
            # 然后判断ABN和AO的内积, 大于0则说明原点在ABN方向, 否则在反方向.
            """
            return cross_2d(cross_2d(a, b), c)[:2]

        ab_normal = get_abc_cross(ac, ab, ab)
        ab_normal
        ac_normal = get_abc_cross(ab, ac, ac)
        ac_normal


    # --- 判断单纯形是否包含原点
    def ContainsOrigin(a, b, c):
        # 判断二维单纯形(三角形)是否包含原点
        return 1

        1





    1
    pass
